package com.hzit.manager.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.hzit.manager.entity.group.Specification;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.hzit.manager.entity.SpecificationEntity;
import com.hzit.manager.service.SpecificationService;
import com.hzit.common.utils.PageUtils;
import com.hzit.common.utils.R;


/**
 * @author hbxfwf
 * @email 2568783935@gmail.com
 * @date 2023-06-06 15:58:41
 */
@RestController
@RequestMapping("manager/specification")
public class SpecificationController {
	@Autowired
	private SpecificationService specificationService;

	/**
	 * 列表
	 */
	@GetMapping("/list")
	public R list(@RequestParam Map<String, Object> params) {
		PageUtils page = specificationService.queryPage(params);

		return R.ok().put("page", page);
	}

	// 查询所有规格
	@GetMapping("/findAll")
	public R findAll() {
		List<SpecificationEntity> list = specificationService.list();
		return R.ok().put("list",list);
	}

	/**
	 * 信息
	 */
	@GetMapping("/info/{id}")
	public R info(@PathVariable("id") String id) {
		Specification specification = specificationService.findById(id);

		return R.ok().put("specification", specification);
	}

	/**
	 * 保存
	 */
	@PostMapping("/save")
	public R save(@RequestBody Specification specification) {
		specificationService.save(specification);

		return R.ok();
	}

	/**
	 * 修改
	 */
	@PutMapping("/update")
	public R update(@RequestBody Specification specification) {
		specificationService.update(specification);

		return R.ok();
	}

	/**
	 * 删除
	 */
	@DeleteMapping("/delete")
	public R delete(@RequestBody String[] ids) {
		specificationService.removeByIds(Arrays.asList(ids));

		return R.ok();
	}

}
